import urllib.request,re

url='http://www.qq.com'
user_agent = 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'
headers = { 'User-Agent' : user_agent }
pattern=re.compile(r'<ul bosszone="newsarea1">(.*?)</ul>')
pattern2=re.compile(r'qiushi_tag_(\d*)')

try:
    request = urllib.request.Request(url,headers=headers)
    response=urllib.request.urlopen(request)
    content=response.read().decode('gbk')
    print(content)
    items=pattern.findall(content)
    for item in items:
        print(item)
except urllib.error.URLError as e:
    if hasattr(e,"code"):
        print(e.code)
    if hasattr(e,"reason"):
        print(e.reason)